# -*- coding: UTF-8 -*- #
"""
-------真正的勇士， 敢于直面惨淡的Warning、 敢于正视淋漓的Error-----
@author : 贾鹏博
@file : 7、响应结果.py
@time : 2022/5/14 21:38
"""

"""
响应结果：
    基本信息：r.url - 路径 ，  r.status_code - 状态码 ， r.headers  - 响应头 ， r.cookies - 服务器注入的 cookie
    响应结果：
        r.text = r.encoding + r.content
        r.json() = r.encoding + r.content + content type json 格式
        r.raw.read(10)
    对应的请求内容： r.request
"""

import requests


class TestDemo:

    def test_header(self):
        r = requests.get('https://httpbin.testing-studio.com/get', headers={'h': "header demo"})
        # 结果是 ： 200
        print(r.status_code)
        """
        {
          "args": {}, 
          "headers": {
            "Accept": "*/*", 
            "Accept-Encoding": "gzip, deflate", 
            "H": "header demo", 
            "Host": "httpbin.testing-studio.com", 
            "User-Agent": "python-requests/2.27.1", 
            "X-Forwarded-Host": "httpbin.testing-studio.com", 
            "X-Forwarded-Scheme": "https", 
            "X-Scheme": "https"
          }, 
          "origin": "172.17.56.110", 
          "url": "https://httpbin.testing-studio.com/get"
        }
        """
        print(r.text)
        # 结果是 ： {'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'H': 'header demo', 'Host': 'httpbin.testing-studio.com', 'User-Agent': 'python-requests/2.27.1', 'X-Forwarded-Host': 'httpbin.testing-studio.com', 'X-Forwarded-Scheme': 'https', 'X-Scheme': 'https'}, 'origin': '172.17.56.110', 'url': 'https://httpbin.testing-studio.com/get'}
        print(r.json())
        assert r.status_code == 200
        assert r.json()['headers']['H'] == "header demo"
